﻿using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CFFKController : Controller
    {
        private readonly IMapper mapper;
        private readonly ICFFKService cFFKService;

        public CFFKController(IMapper mapper, ICFFKService cFFKService)
        {
            this.mapper = mapper;
            this.cFFKService = cFFKService;
        }
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 分页查询方法
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IActionResult> CFFKSelect(int pageIndex,int pageSize)
        {
            List<CFFK> cFFKs = await cFFKService.CFFKSelect(pageIndex,pageSize);
            return Json(cFFKs);
        }

        /// <summary>
        /// 查询数据总数
        /// </summary>
        /// <returns></returns>
        public IActionResult CFFKSelectCount()
        {
            int count = cFFKService.CFFKSelectCount();
            return Json(count);
        }

        /// <summary>
        /// 添加1级机构表数据页面
        /// </summary>
        /// <param name="cFFK"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult CFFKInsert()
        {
            return View();
        }

        /// <summary>
        /// 添加1级机构表数据
        /// </summary>
        /// <param name="cFFK"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CFFKInsert(CFFKAddDto cFFK)
        {
            int num = await cFFKService.CFFKInsertAsync(cFFK);
            return Json(num);
        }

        /// <summary>
        /// 删除1级结构表数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[HttpDelete]
        [HttpDelete("CFFK/CFFKDeleteAsync")]
        public async Task<IActionResult> CFFKDeleteAsync(CFFKDeleteDto cFFKDeleteDto)
        {
            int num = await cFFKService.CFFKDeleteAsync(cFFKDeleteDto);
            return Json(num);
        }

        /// <summary>
        /// 修改1级结构表数据页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult CFFKUpdate(int id)
        {
            TempData["Id"] = id;
            return View();
        }

        /// <summary>
        /// 按id查询1级结构表数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("CFFK/CFFKSelectByIdAsync")]
        public async Task<IActionResult> CFFKSelectByIdAsync()
        {
            int id = (int)TempData["Id"];
            return Json(await cFFKService.CFFKSelectByIdAsync(id));
        }

        /// <summary>
        /// 修改1级结构表数据
        /// </summary>
        /// <param name="cFFK"></param>
        /// <returns></returns>
        [HttpPost("CFFK/CFFKUpdateAsync")]
        public async Task<IActionResult> CFFKUpdateAsync(CFFK cFFK)
        {
            int num = await cFFKService.CFFKUpdateAsync(cFFK);
            return Json(num);
        }

        /// <summary>
        /// 按名称查询1级结构表数据
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<IActionResult> CFFKSelectByName(string name)
        {
            return Json(await cFFKService.CFFKSelectByName(name));
        }
    }
}
